package com.boang;

import com.boang.dao.ClaDao;
import com.boang.po.Cla;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/*
  @author: 13813
  @date: 2024/7/19 11:08
*/
public class Test01 {
    public synchronized static void main(String[] args) throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession(true);
        //获取ClaDao接口实现类对象
        ClaDao claDao = sqlSession.getMapper(ClaDao.class);
//        getClaList(claDao); //全表查询
//        addCla(claDao); //添加
//        sqlSession.commit();//提交事务
//        deleteClaById(claDao); //删除
        selectClaByIdAndName(claDao);
    }

    private static void selectClaByIdAndName(ClaDao claDao) {
        Cla cla = claDao.selectClaByIdAndName(1, "47期");
        System.out.println(cla);
    }

    private static void addCla(ClaDao claDao) {
        Cla cla = new Cla(1, "300期", 300);
        claDao.insertCla(cla);
    }

    private static void getClaList(ClaDao claDao) {
        List<Cla> list = claDao.selectClaList();
        System.out.println(list);
    }

    private static void deleteClaById(ClaDao claDao) {
        claDao.deleteClaById(35);
    }


}
